package com.hs.biye.controller.admin;


import com.hs.biye.constant.MessageConstant;
import com.hs.biye.excepction.BaseException;
import com.hs.biye.model.DTO.PatientRequest;
import com.hs.biye.model.DTO.RoomRequest;
import com.hs.biye.model.VO.PatientVo;
import com.hs.biye.model.VO.RoomVo;
import com.hs.biye.model.enums.RoomTypeEnum;
import com.hs.biye.model.reslut.Result;
import com.hs.biye.model.reslut.ResultPage;
import com.hs.biye.service.RoomService;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.*;

@RestController
@RequestMapping("/admin/room")
public class RoomController {

    @Resource
    private RoomService roomService;


    @PostMapping("/gets/{id}")
    public Result <List<RoomVo>> getRoomIdAndNumber( @PathVariable Integer id) {
        if (id == null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        List<RoomVo> roomByAndRoomNumber = roomService.getRoomByAndRoomNumber(id);
        if (CollectionUtils.isEmpty(roomByAndRoomNumber)){
            throw new BaseException(MessageConstant.NOT_QUERY);
        }
        return Result.success(roomByAndRoomNumber);
    }

    @PostMapping("/pages")
    public ResultPage<RoomVo> getRoom(@RequestBody RoomRequest roomRequest){
        if (roomRequest == null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        ResultPage<RoomVo> pageRoom = roomService.getPageRoom(roomRequest);
        if (pageRoom == null){
            throw new BaseException(MessageConstant.NOT_QUERY);
        }
        return pageRoom;
    }

    @GetMapping("/one/{id}")
    public Result<RoomVo> getRoomById(@PathVariable Integer id){
        if (id == null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        RoomVo roomVo =  roomService.getRoomById(id);
        return Result.success(roomVo);
    }


    //获取房间类型
    @GetMapping("/type")
    public Result<List<Map<String,String>>> getType(){
        RoomTypeEnum[] values = RoomTypeEnum.values();
        List<Map<String,String>>  res = new ArrayList<>();
        for (RoomTypeEnum type:values){
            Integer code = type.getCode();
            String value = type.getValue();
            Map<String,String > map = new HashMap<>();
            map.put("type",code.toString());
            map.put("typeName", value);
            res.add(map);
        }
        return Result.success(res);
    }


    @PostMapping("/add")
    public Result<Boolean> addRoom(@RequestBody RoomRequest roomRequest){
        if (roomRequest == null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        Boolean b = roomService.addRoom(roomRequest);
        return Result.success(b);
    }

    @PostMapping("/update")
    public Result<Boolean> updateRoom(@RequestBody RoomRequest roomRequest){
        if (roomRequest == null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        Boolean b = roomService.updateRoom(roomRequest);
        return Result.success(b);
    }

    @GetMapping("/delete/{id}")
    public Result<Boolean> deleteRoom(@PathVariable Integer id){
        if (id == null){
            throw new BaseException(MessageConstant.PAR_NOT_RIGHT);
        }
        Boolean b = roomService.deleteRoom(id);
        return Result.success(b);
    }
}
